package com.own.business.log.login.persistence.entity.vo;

import com.own.business.log.login.persistence.entity.po.LogLogin;
import com.own.component.common.base.entity.vo.BaseBeanVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * LogLoginVo
 *
 * @author chenxueli
 * @date 2023-08-08 17:14:57
 */
@Schema(title = "登录日志持久化" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class LogLoginVo extends BaseBeanVo<LogLogin> implements Serializable {

    @Schema(title = "登录账号")
    private String loginAccount;

    @Schema(title = "登录类型")
    private String loginType;

    @Schema(title = "登录编码")
    private String loginCode;

    @Schema(title = "用户id")
    private Long userId;

    @Schema(title = "用户名")
    private String userName;

    @Schema(title = "ip地址")
    private String ip;

    @Schema(title = "客户端")
    private String client;

    @Schema(title = "token")
    private String token;

    @Schema(title = "操作内容")
    private String extra;

    @Schema(title = "登录状态 1=成功 2=失败")
    private Integer status;

    @Schema(title = "链路id")
    private String traceId;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public LogLoginVo(@NonNull LogLogin entity) {
        super(entity);
        this.loginAccount = entity.getLoginAccount();
        this.loginType = entity.getLoginType();
        this.loginCode = entity.getLoginCode();
        this.userId = entity.getFkUserId();
        this.userName = entity.getUserName();
        this.ip = entity.getIp();
        this.client = entity.getClient();
        this.token = entity.getToken();
        this.extra = entity.getExtra();
        this.status = entity.getStatus();
        this.traceId = entity.getTraceId();
    }

    /**
     * 转po对象
     *
     * @param entity 原对象
     * @return po对象
     */
    @Override
    public LogLogin toPo(LogLogin entity) {
        if (entity == null) {
            entity = new LogLogin();
        }
        entity.setLoginAccount(this.loginAccount);
        entity.setLoginType(this.loginType);
        entity.setLoginCode(this.loginCode);
        entity.setFkUserId(this.userId);
        entity.setUserName(this.userName);
        entity.setIp(this.ip);
        entity.setClient(this.client);
        entity.setToken(this.token);
        entity.setExtra(this.extra);
        entity.setStatus(this.status);
        entity.setTraceId(this.traceId);
        return super.toPo(entity);
    }

}
